package com.sanuo.pico.adapter;


import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.menu.app.activity.BaseCustomInfoActivity;
import com.menu.app.adapter.BaseCusRecordAdapter;
import com.menu.app.bean.DayRecord;
import com.menu.app.databinding.CusRecordItemBinding;
import com.menu.app.db.CusUsageDao;
import com.menu.app.db.bean.CusUsage;
import com.menu.app.db.bean.Custom;
import com.menu.app.util.Utils;
import com.plata.base.ui.MyRecyclerView;
import com.sanuo.pico.bean.WorkParam;
import com.sanuo.pico.databinding.RecordContentBinding;
import com.sanuo.pico.event.VbEvent;

public class CusRecordAdapter extends BaseCusRecordAdapter {

    public CusRecordAdapter(BaseCustomInfoActivity activity, CusUsageDao dao, Custom custom, MyRecyclerView recyclerView, boolean isAdmin) {
        super(activity, dao, custom, recyclerView, isAdmin);
    }

    @Override
    protected ItemHolder onCreateViewHolder(CusRecordItemBinding binding, int type, ItemHolder holder) {
        RecordContentBinding tmp = RecordContentBinding.inflate(LayoutInflater.from(binding.getRoot().getContext()), binding.left, false);
        binding.left.addView(tmp.getRoot(), 0);
        holder.contentBinding = tmp;

        return holder;
    }

    @Override
    protected void setInfo(CusUsage data, Object obj) {
        if (obj instanceof RecordContentBinding) {
            RecordContentBinding binding = (RecordContentBinding) obj;
            try {
                Gson g = Utils.getGson();
                WorkParam param = g.fromJson(g.toJson(data.info), WorkParam.class);
                binding.freq.setText(param.freq + "");
                binding.energy.setText(param.energy + "");
                binding.wave.setText(VbEvent.getName(param.wave));
                binding.shot.setText(data.point + "");
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected void bindHolder(RecyclerView.ViewHolder holder, int position) {
        super.bindHolder(holder, position);
        ((ItemHolder) holder).binding.more.setVisibility(View.GONE);
    }

    @Override
    protected boolean deletePic(DayRecord day) {
        return false;
    }
}
